<?php

namespace App\Services;

use App\Models\Crm_Role;

class RoleService
{
    public function getRoleList($params)
    {
        $result = Crm_Role::getFilter($params)->get();
        $list['list'] = $result;
        return ['status' => true,'code' => 200,'data' => $list];
    }

    public function getList($params)
    {
        $result = Crm_Role::getFilter($params)->Nodel()->paginate($params['pageSize']);
        foreach ($result as $key => $value){
            if($value->pid == 0){
                $result[$key]['parent_role_name'] = '无';
                $result[$key]['nums'] = $value->hasManyRole()->count();
            }else{
                $result[$key]['parent_role_name'] = $value->hasOneRole->role_name;
                $result[$key]['nums'] = 0;
            }
        }
        $result->data = $result->makeHidden(['hasOneRole']);
        $list['list'] = $result->items();
        $list['total'] = $result->total();
        return $list;
    }

}
